home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / OOP.SWG / 0029_Valid Directories.pas < prev    next >
Pascal/Delphi Source File  |  1994-01-27  |  2KB  |  77 lines

  1. {
  2.    For you TV programmers out there, here is a neat little
  3.    TValidator object for you - it verifies that the DIRECTORY
  4.    entered in a TInputLine is valid and currently exists.
  5. }
  6.  
  7. Unit DirValid;
  8.  
  9. INTERFACE
  10.  
  11. Uses
  12.   Objects,
  13.   Validate;
  14.  
  15. Type
  16.   PDirValidator = ^TDirValidator;
  17.   TDirValidator = OBJECT(TValidator)
  18.     constructor Init;
  19.  
  20.     procedure Error; virtual;
  21.     function IsValid(const S : string) : boolean; virtual;
  22.   end;
  23.  
  24. IMPLEMENTATION
  25.  
  26. Uses
  27.   Dos,
  28.   MsgBox;
  29.  
  30. Function ExistDir(d : string) : boolean;
  31. VAR
  32.   S : SearchRec;
  33. BEGIN
  34.   {$I-}
  35.   FindFirst(d, Directory, S);
  36.   {$I+}
  37.   if DOSError = 0 then
  38.   BEGIN
  39.     if Directory = (S.attr and Directory) then
  40.       ExistDir := TRUE
  41.     ELSE
  42.       ExistDir := FALSE;
  43.     END
  44.   ELSE
  45.     ExistDir := FALSE;
  46.   END;
  47.  
  48. constructor TDirValidator.Init;
  49. begin
  50.   inherited Init;
  51. end;
  52.  
  53. procedure   TDirValidator.Error;
  54. begin
  55.   MessageBox('Directory does not exist!', nil, mfError + mfOKButton);
  56. end;
  57.  
  58. function    TDirValidator.IsValid(const S : string) : boolean;
  59. var
  60.   d : string;
  61. begin
  62.   if s='' then  {always return TRUE when entry string is empty}
  63.   begin
  64.     IsValid := TRUE;
  65.     EXIT;
  66.   end;
  67.   d := s;
  68.   if s[Length(d)] = '\' then
  69.     Delete(d, Length(d), 1); {allows flexibility - TV & TP expect
  70.                                paths to NOT terminate in a \ }
  71.   if ExistDir(d) then
  72.     IsValid := TRUE   {directory exists}
  73.   else
  74.     IsValid := FALSE; {directory does not exist}
  75. end;
  76.  
  77. end.